home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog6.arj / BRUSH.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  1.9 KB  |  85 lines

  1. { brush.pas -- Draw figures painted with a custom brush }
  2.  
  3. program Brush;
  4.  
  5. {$R brush.res}
  6.  
  7. uses WinTypes, WinProcs, WObjects;
  8.  
  9. const
  10.  
  11.   id_Pattern = 200;    { Resource ID of any 8-by-8 bitmap }
  12.  
  13. type
  14.  
  15.   BrushApplication = object(TApplication)
  16.     procedure InitMainWindow; virtual;
  17.   end;
  18.  
  19.   PBrushWindow = ^BrushWindow;
  20.   BrushWindow = object(TWindow)
  21.     Pattern: HBrush;  { Handle to brush made from bitmap }
  22.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  23.     destructor Done;
  24.       virtual;
  25.     procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
  26.       virtual;
  27.   end;
  28.  
  29.  
  30. { BrushApplication }
  31.  
  32. {- Initialize BrushApplication object's window }
  33. procedure BrushApplication.InitMainWindow;
  34. begin
  35.   MainWindow := New(PBrushWindow, Init(nil, 'Brush'))
  36. end;
  37.  
  38.  
  39. { BrushWindow }
  40.  
  41. {- Construct BrushWindow object }
  42. constructor BrushWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  43. var
  44.   H: HBitmap;
  45. begin
  46.   TWindow.Init(AParent, ATitle);
  47.   H := LoadBitmap(HInstance, PChar(id_Pattern));
  48.   Pattern := CreatePatternBrush(H);
  49.   DeleteObject(H)
  50. end;
  51.  
  52. {- Destroy BrushWindow object and the custom brush }
  53. destructor BrushWindow.Done;
  54. begin
  55.   DeleteObject(Pattern);
  56.   TWindow.Done
  57. end;
  58.  
  59. {- Display a few objects filled with the custom brush }
  60. procedure BrushWindow.Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
  61. var
  62.   OldBrush: HBrush;
  63. begin
  64.   OldBrush := SelectObject(PaintDC, Pattern);
  65.   Rectangle(PaintDC, 10, 10, 100, 90);
  66.   Ellipse(PaintDC, 90, 80, 200, 160);
  67.   SelectObject(PaintDC, OldBrush)
  68. end;
  69.  
  70. var
  71.  
  72.   BrushApp: BrushApplication;
  73.  
  74. begin
  75.   BrushApp.Init('BrushApp');
  76.   BrushApp.Run;
  77.   BrushApp.Done
  78. end.
  79.  
  80.  
  81. {--------------------------------------------------------------
  82.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  83.   Revision 1.00    Date: 2/26/1991
  84. ---------------------------------------------------------------}
  85.